<!DOCTYPE html>
<html class="no-js">

<head>
    <meta charset="utf-8">
    <title>校园订水</title>
    <meta name="description" content="">
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui, user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/assets/base/restaurant/css/common.css">
    <link rel="stylesheet" href="/assets/base/restaurant/css/fonts.css">
    <link rel="stylesheet" href="/assets/base/restaurant/css/load.css">
    <link rel="stylesheet" href="/assets/base/restaurant/css/index.css">
	<link rel="stylesheet" href="/assets/base/repair/js/sweetalert/lib/sweet-alert.css">
	<style>
		.btn-box .checked{
			color: #fff;
			background: #27a1d8;
		}
		.btn-box .checked:visited{
			color: #fff;
			background: #27a1d8;
		}
		.form-box .form-list{
			width: 50%;
			position: relative;
		}
		.form-box .form-list:first-child{
			border-right: 1px solid #ccc;
		}
		.form-box .form-list select{
			width: 100%;
			border: none;
			padding: 10px;
		}
		.form-box .form-list .triangle{
			border: 6px solid;
			border-color: #000 transparent transparent transparent;
			position: absolute;
			right: 10px;
			top: 50%;
			margin-top: -3px;
		}
	</style>
</head>
<body>
<div class="wraper">
	<div class="top">
		<p>全部订单</p>
	</div>
    <form action="{BEESCRM::U('base/water/sendList')}" method="post" id="search-form">
	<div class="form-box clearfix">
		<div class="form-list pull-left">
            <select class="select-region form-control pull-left relate-info" name="community_id"
                    id="community_id">
                <option value='0'
                <eq name="community_id" value='0'>selected</eq>
                >请选择园区</option>
                <volist name="community_arr" id="vo">
                    <option value='{BEESCRM:$vo.community_id}'
                    <eq name="community_id" value='$vo.community_id'>selected</eq>
                    >{BEESCRM:$vo.community_name}</option>
                </volist>
            </select>
			<span class="triangle"></span>
		</div>
		<div class="form-list pull-left">
            <select class="select-region form-control pull-left relate-info" name="building_id"
                    id="building_id">
                <option value='0'
                <eq name="building_id" value='0'>selected</eq>
                >请选择楼幢</option>
                <volist name="building_name" id="vo">
                    <option value='{BEESCRM:$vo.building_id}'
                    <eq name="building_id" value='$vo.building_id'>selected</eq>
                    >{BEESCRM:$vo.building_name}</option>
                </volist>
            </select>
			<span class="triangle"></span>
		</div>
	</div>
	<input type="hidden" value="{BEESCRM:$pageCount}" id="page_count">
	<input type="hidden" id="waterId" value="{BEESCRM:$waterId}">
	<div class="datalist">
	<volist name="orderList" id="vo">
		<div class="order-dtl">
			<p>订单编号：{BEESCRM:$vo.order_sn}</p>
			<p>下单时间：{BEESCRM:$vo.pay_time|date='Y/m/d H:i',###}</p>
			<hr/>
			<p>收货人：{BEESCRM:$vo.username}</p>
			<p>联系电话：<if condition="$vo['mobile']"><a href="tel://{BEESCRM:$vo.mobile}" style="color: #2a2a2a">{BEESCRM:$vo.mobile} <span class="iconfont icon-dianhua1" style="color: #4ba63d;"></span></a></if></p>
			<p>地址:{BEESCRM:$vo.address}</p>
			<hr/>
			<p class="text-gray btm10">详情</p>

			<p>{BEESCRM:$vo.goods_name}<span class="pull-right">x{BEESCRM:$vo.goods_num}</span></p>
            <if condition="$vo.snack_arr">
                <volist name="vo.snack_arr" id="vol">
                    <p>{BEESCRM:$vol.snack_name}<span class="pull-right">x{BEESCRM:$vol.snack_num}</span></p>
                </volist>
            </if>
			<hr/>
			
			<if condition="$vo['status'] eq 1">
				<a href="javascript:void(0);" class="c-btn btn-blue send" data-id="{BEESCRM:$vo.order_id}">确认派送</a>
			</if>
			<if condition="$vo['status'] eq 2">
				<a href="javascript:void(0);" class="c-btn complete" style="background:#EE3D11" data-id="{BEESCRM:$vo.order_id}">确认完成</a>
			</if>
			<if condition="$vo['status'] eq 3">
				<p class="text-gray text-center">派送完成</p>
			</if>
			<if condition="$vo['status'] eq 4">
				<p class="text-gray text-center">已收货</p>
			</if>
            <if condition="$vo['status'] eq 5">
                <p class="text-gray text-center">已评价</p>
            </if>
		</div>
		<div class="wave-bottom"></div>
	</volist>
		</div>

	<div class="btn-box">
		<a href="javascript:void(0)" class="btn checked" id="notdone">未完成订单</a>
		<a href="javascript:void(0)" class="btn" id="done">已完成订单</a>
	</div>
    </form>
</div>

<include file="Restaurant:commonJS" />
<script src="/assets/activity/vote/js/classie.js"></script>
<script src="/assets/base/restaurant/js/order.js"></script>
<script src="/assets/activity/vote/js/modalEffects.js"></script>
<script>
	$(function(){
		$(document).on('click','.send',function(){
			var id = $(this).data('id');
			var waterId = $('#waterId').val();
			$.confirm('确认派送吗？', drop);
			function drop() {
				var json = {};
				var data = {};
				data.id = id;
				json.data = data;
				json.url = '/base/water/confirmSend/water_id/'+waterId;
				json.method = 'post';
				json.type = 'json';
				$.getAjax(json, true, reload, '');
			}
		});

		$(document).on('click','.complete',function(){
			var id = $(this).data('id');
			var waterId = $('#waterId').val();
			$.confirm('确认完成吗？', drop);
			function drop() {
				var json = {};
				var data = {};
				data.id = id;
				json.data = data;
				json.url = '/base/water/confirmSendOver/water_id/'+waterId;
				json.method = 'post';
				json.type = 'json';
				$.getAjax(json, true, reload, '');
			}
		});
	});
	function reload() {
		setTimeout('location.reload()',1000);
	}

    //二级联动获取楼幢名
    $(document).on('change', '#community_id', function () {
        var data={};
        var num = '';
        data.community_id = $('#community_id').val();
        $.ajax({
            'url': "/base/water/buildingName",
            'data': data,
            'dataType': 'json',
            'type': 'GET',
            success:function(data){
                if(data.status == 'S'){
                    var op = $('#building_id');
                    op.html("");
                    op.append("<option value=''>请选择楼幢</option>");
                    $.each(data.data, function (i, item) {
                        op.append("<option value=" + item.building_id + ">" + item.building_name + "</option>");
                    });
                    /*$("#done").removeClass("checked");
                    $("#notdone").removeClass("checked");*/
                }else{
                    var op = $('#building_id');
                    op.html("");
                    op.append("<option value=''>请选择楼幢</option>");
                    if($('#notdone').hasClass('checked')){
                        data.num = 1;
                        showAll(data);
                    } else if($('#done').hasClass('checked'))
                    {
                        data.num = 2;
                        showAll(data);
                    }
                }
            }
        });
    });
    //三级联动获取页面
    $(document).on('change', '#building_id', function () {
        var data={};
        data.building_id = $('#building_id').val();
        if ($('#notdone').hasClass('checked')) {
            data.num = 1;
        };
        if ($('#done').hasClass('checked')) {
           data.num = 2;
        };
        //alert(data.building_id);
        showAll(data);
    });
    function showAll(data){
        $.ajax({
            'url':"/base/water/getArr",
            'data':data,
            'dataType':'json',
            'type':'GET',
            success: function (data) {
                var string = '';
                var opt = $('.datalist');
                opt.html("");
                var str = '';
                $.each(data.data, function (i,val) {

                    var unknown = '不详'
                    string = string+'<div class="order-dtl">'
                    +'<p>订单编号：'+val.order_sn+'</p>';
                    if(val.pay_time){
                        /*var pay_time =getLocalTime(val.pay_time);
                        //var pay_time = new Date().Format("yyyy-MM-dd hh:mm:ss");*/
                        string = string+'<p>下单时间：'+val.pay_time+'</p>'
                    }else{
                        string = string+'<p>下单时间：'+unknown+'</p>'
                    }
                    string =string +'<hr/>'
                    +'<p>收货人：'+val.username+'</p>'
                    +'<p>联系电话：<a href="tel://'+val.mobile+'" style="color: #2a2a2a">'+val.mobile+'<span class="iconfont icon-dianhua1" style="color: #4ba63d;"></span></a></p>';
                    if(val.address){
                        string =string+'<p>地址：'+val.address+'</p>'
                    } else if(val.community_name && val.building_name && val.floor && val.room)
                    {
                        string =string+'<p>地址：'+val.community_name+val.building_name+val.floor+val.room+'</p>'
                    }else if(val.community_name && val.building_name && val.floor)
                    {
                        string =string+'<p>地址：'+val.community_name+val.building_name+val.floor+'</p>'
                    }else if(val.community_name && val.building_name)
                    {
                        string =string+'<p>地址：'+val.community_name+val.building_name+'</p>'
                    } else if(val.community_name)
                    {
                        string =string+'<p>地址：'+val.community_name+'</p>'
                    }
                    else
                    {
                        string =string+'<p>地址：'+unknown+'</p>'
                    }
                    string =string+'<hr/>'
                    +'<p class="text-gray btm10">详情：</p>'
                    +'<p>'+val.goods_name+'<span class="pull-right">'+'x'+val.goods_num+'</span></p>';
                    if(val.snack_arr){
                        $.each(val.snack_arr, function (i,value){
                            string =string+'<p>'+value.snack_name+'<span class="pull-right">'+'x'+value.snack_num+'</span></p>';
                        })
                    }
                    string =string+'<hr/>';

                        if(val.status == 1){
                            string =string+ '<a href="javascript:void(0);" class="c-btn btn-blue send" data-id="'+val.order_id+'">确认派送</a>';
                        }
                        if(val.status == 2){
                            string =string+ '<a href="javascript:void(0);" class="c-btn complete" style="background:#EE3D11" data-id="'+val.order_id+'">确认完成</a>';
                        }
                        if(val.status == 3){
                            string =string+ '<p class="text-gray text-center">派送完成</p>';
                        }
                        if(val.status == 4){
                            string =string+ '<p class="text-gray text-center">已收货</p>';
                        }
                        if(val.status == 5){
                            string =string+ '<p class="text-gray text-center">已评价</p>';
                        }
                    string =string+'</div>';
                    string =string+'<div class="wave-bottom"></div>';
                });
                $('.datalist').append(string);
            }
        })
    }
    /*function getLocalTime(nS) {
        return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
    }*/

    //未完成
    $('#notdone').on('click', function () {
        var data={};
        var building_id = $('#building_id').val();
        data.num = 1;
        showAll(data);
        $(this).addClass("checked notdone");
        $("#done").removeClass("checked done");
        if(building_id){
            var opt = $('#community_id');
            var op = $('#building_id');
            $('#community_id').prop('selectedIndex', 0);
            $('#building_id').prop('selectedIndex', 0);
        }
    });
    //未完成
    $('#done').on('click', function () {
        var data={};
        var building_id = $('#building_id').val();
        data.num = 2;
        showAll(data);
        $(this).addClass("checked done");
        $("#notdone").removeClass("checked notdone");
        if(building_id){
            var opt = $('#community_id');
            var op = $('#building_id');
            $('#community_id').prop('selectedIndex', 0);
            $('#building_id').prop('selectedIndex', 0);
        }
    });
</script>
</body>
</html>
